<?php

namespace App\Shop\Providers;
use App\Shop\Contracts\CartInterface;
use App\Shop\Contracts\GoodsClassInterface;
use App\Shop\Contracts\GoodsInterface;
use App\Shop\Repositories\DbCartRepository;
use App\Shop\Repositories\DbGoodsClassRepository;
use App\Shop\Repositories\DbGoodsRepository;
use Illuminate\Support\Facades\Route;
use Illuminate\Support\ServiceProvider;

/**
 * 商城商品
 * Class GoodsProvider
 * @package App\Goods\Providers
 */

class GoodsProvider extends ServiceProvider
{

    protected $namespace = 'App\Shop\Controllers';
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        //require __DIR__.'/../admin_routes.php';  //后台路由
        //require __DIR__.'/../routes.php';          //前台路由
        $this->mapWebRoutes();
    }

    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        $this->app->bind(GoodsInterface::class, DbGoodsRepository::class); //产品操作类
        $this->app->bind(GoodsClassInterface::class, DbGoodsClassRepository::class); //产品分类操作类
        $this->app->bind(CartInterface::class, DbCartRepository::class); //购物车操作类
    }
    /**
     * Define the "web" routes for the application.
     *
     * These routes all receive session state, CSRF protection, etc.
     *
     * @return void
     */
    protected function mapWebRoutes()
    {
        Route::middleware('web')
            ->namespace($this->namespace)
           ->group(__DIR__."/../admin_routes.php");// ->group(__DIR__."/../routes.php")

        Route::middleware('web')
            ->namespace($this->namespace)
            ->group(__DIR__."/../routes.php");
        //这边可以在分为权限的比方说
//        Route::middleware('permission')
//            ->namespace($this->namespace)
//            ->group(__DIR__."/../auth_routes.php");  //需要权限的路由
    }
}
